def isPrime(x):
    if x == 1: return False
    test = True
    k = x - 1
    while k > 1:
        if not x % k:
            test = False
            break
        k -= 1 
    return test

n = input()
r = []
for i in range(len(n)):
    for k in range(i + l, len(n) + 1):
        a = int(n[i:k])
        if isPrime(x):
            r += [a]
print(max(r) if r else 0)
